﻿namespace WMS6.Web
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web;
    using WMS6.Web.CustomizeReportServiceRef;

    public class CustomizeReportServiceClientProxy : BasePage
    {
        public static CustomizeReportServiceClientProxy GetInstance()
        {
            return new CustomizeReportServiceClientProxy();
        }

        public DataSet GetLPSaleReport(LPSaleReportQueryEntity lPSaleReportQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            CustomizeReportServiceClient client = new CustomizeReportServiceClient("WSHttpBinding_ICustomizeReportService");
            try
            {
                ds = client.GetLPSaleReport(lPSaleReportQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public DataSet GetNSNPerformanceReportByDataSet(NSNPerformanceReportQueryEntity nsnPerformanceReportQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            CustomizeReportServiceClient client = new CustomizeReportServiceClient("WSHttpBinding_ICustomizeReportService");
            try
            {
                ds = client.GetNSNPerformanceReportByDataSet(nsnPerformanceReportQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public DataSet GetTNTDailyInventoryRptDataSet(InventoryQueryEntity inventoryQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            CustomizeReportServiceClient client = new CustomizeReportServiceClient("WSHttpBinding_ICustomizeReportService");
            try
            {
                ds = client.GetTNTDailyInventoryRptDataSet(inventoryQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public DataSet GetTNTInOutStockInvRptDataSet(TNTInOutStockInvRptQueryEntity tntInOutStockInvRptQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            CustomizeReportServiceClient client = new CustomizeReportServiceClient("WSHttpBinding_ICustomizeReportService");
            try
            {
                ds = client.GetTNTInOutStockInvRptDataSet(tntInOutStockInvRptQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public DataSet GetYITAISerialNoInOutReport(YITAISerialNoInOutReportQueryEntity serialNoInOutReportQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            CustomizeReportServiceClient client = new CustomizeReportServiceClient("WSHttpBinding_ICustomizeReportService");
            try
            {
                ds = client.GetYITAISerialNoInOutReport(serialNoInOutReportQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        private PubParasInfo InitPubParasInfo()
        {
            if (base.UserInfo != null)
            {
                return new PubParasInfo { UserID = base.UserInfo.UserID, UserLanguage = base.UserInfo.Preference.Lang, CurrentWH = base.UserInfo.CurrentWH };
            }
            HttpContext.Current.Response.Redirect("../Login.aspx?from=Logout", true);
            return null;
        }

        public string UpdateYITAISerialNoInOutReportFlag(List<string> transIDs, List<string> otTransIDs)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = "";
            CustomizeReportServiceClient client = new CustomizeReportServiceClient("WSHttpBinding_ICustomizeReportService");
            try
            {
                result = client.UpdateYITAISerialNoInOutReportFlag(transIDs, otTransIDs, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }
    }
}

